using Nethouse.Lib.EventBus;

namespace Nethouse.Lib.Mvp
{
    public abstract class Presenter<TView> : IPresenter<TView> where TView: IView
    {
        protected TView View
        {
            get; private set;
        }

        private IEventBus eventBus = null;

        protected IEventBus EventBus
        {
            get { return getEventBus(); }
        }

        private IEventBus getEventBus()
        {
            if (eventBus == null)
            {
                eventBus = Nethouse.Lib.EventBus.EventBus.GetRequestHostedEventBus();
            }

            return eventBus;
        }

        public void MvpInit(IView view, bool triggerViewCreated)
        {
            this.View = (TView) view;

            if (triggerViewCreated)
            {
                ViewCreated();
            }

            ViewLoaded();
        }

        protected virtual void ViewCreated()
        {
        }

        protected virtual void ViewLoaded()
        {
        }
    }
}